<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">报告批准</block>
		</cu-custom>
		<scroll-view scroll-y class="page">
			<view style="height: 10rpx;"></view>
			<view v-if="dataList.length==0" class="no-data">未查询到数据</view>
			<u-report v-else v-for="(item,index) in dataList" :data="item" :key="index">
			</u-report>
		</scroll-view>
		<view class="cu-modal bottom-modal" :class="modalName=='confirm'?'show':''" @tap="hideModal">
			<view class="cu-dialog" @tap.stop="">
				<view class="cu-bar bg-white">
					<view class="action text-blue" @tap="pass(0)">驳回</view>
					<view class="action text-green" @tap="pass(1)">通过</view>
				</view>
				<view style="height: 200rpx;font-size: 30rpx;">
					<view class="inputbox">
						<text class="lg cuIcon-edit"></text>
						<input class="f_input" placeholder="拒绝理由" v-model="formData.approveRemarks"/>
					</view>
<!-- 					<view class="selectbox">
							<view style="flex: 2;">审批组: </view>
							<view class="uni-list-cell" style="color: #000000;text-align: left;flex:3">
								<view class="uni-list-cell-db">
									<picker @change="bindPickerChange" :value="index" :range="array">
										<view class="uni-input" v-if="index==-1">请选择</view>
										<view  v-else class="uni-input">{{array[index]}}</view>
									</picker>
								</view>
							</view>
							<view style="flex: 2;">审批人: </view>
							<view class="uni-list-cell" style="color: #000000;text-align: left;flex: 3;">
								<view class="uni-list-cell-db">
									<picker :value="index2" :range="array2">
										<view class="uni-input" v-if="index2==-1">请选择</view>
										<view v-else class="uni-input">{{array2[index2]}}</view>
									</picker>
								</view>
							</view>
					</view> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import uReport from '../../components/u-audit/u-report.vue'
	export default {
		data() {
			return {
				modalName: null,
				param: {
					page: 1,
					limit: 1000
				},
				dataList: [],
				groupList:[],
				personList:[],
				array: [],
				index: -1,
				array2: [],
				index2: -1,
				formData:{
					reportId:'',
					todoId:'',
					approveRemarks:'',
					version:'',
					groupId:'',
					userIds:[],
					status:''
				}
			}
		},
		onShow: function() {
			this.loadData();
			// this.loadGroup();
			uni.$on('report-audit', (o) => {
				this.modalName = 'confirm'
				this.formData.reportId = o.reportId;
				this.formData.version = o.version;
				this.formData.todoId = o.todoId;
				this.formData.approveRemarks ='';
				this.index = -1;
				this.index2 = -1;
			})
		},
		components: {
			uReport
		},
		methods: {
			loadGroup:function(){
				uni.request({
					url: this.$http + '/biz/bizTodoGroup/listByCondition',
					//data: this.param,
					header: {
						token: uni.getStorageSync("token")
					},
					method: 'POST',
					success: (res) => {
						if (res.statusCode == 200 && res.data.code == 0) {
							console.log(res)
							this.groupList = res.data.list;
							this.array = [];
							for(var i =0;i < this.groupList.length;i++){
								this.array.push(this.groupList[i].groupName);
							}
							if(this.array2.length==0){
								this.loadP(this.groupList[0].groupId)
							}
						} else {
							uni.showToast({
								icon: 'none',
								title: '查询数据失败，请重试！'
							});
						}
					},
					fail: function() {
						uni.showToast({
							icon: 'none',
							title: '服务器请求超时！'
						});
					}
				})
			},
			loadP:function(gid){
				uni.request({
					url: this.$http + '/biz/bizTodoGroup/info/'+gid,
					//data: this.param,
					header: {
						token: uni.getStorageSync("token")
					},
					method: 'POST',
					success: (res) => {
						if (res.statusCode == 200 && res.data.code == 0) {
							this.personList = res.data.bizTodoGroup.userList;
							this.array2 = [];
							for(var i =0;i < this.personList.length;i++){
								this.array2.push(this.personList[i].name);
							}
							console.log(this.array2);
						} else {
							uni.showToast({
								icon: 'none',
								title: '查询数据失败，请重试！'
							});
						}
					},
					fail: function() {
						uni.showToast({
							icon: 'none',
							title: '服务器请求超时！'
						});
					}
				})
			},
			loadData() {
				uni.request({
					url: this.$http + '/biz/bizTodoAssign/reportList?page=1&limit=10000&status=502',
					//data: this.param,
					header: {
						token: uni.getStorageSync("token")
					},
					method: 'POST',
					success: (res) => {
						if (res.statusCode == 200 && res.data.code == 0) {
							this.dataList = res.data.page.list;
						} else {
							uni.showToast({
								icon: 'none',
								title: '查询数据失败，请重试！'
							});
						}
					},
					fail: function() {
						uni.showToast({
							icon: 'none',
							title: '服务器请求超时！'
						});
					}
				})
			},
			hideModal: function() {
				this.modalName = null;
			},
			bindPickerChange: function(e) {
				this.index = e.target.value
				this.index2 = -1;
				this.loadP(this.groupList[this.index].groupId);
			},
			pass:function(f){
				if(f==1){
					this.formData.status = 504;
					// if(this.index!=-1){
					// 	this.formData.groupId = this.groupList[this.index];
					// 	if(this.index2!=-1){
					// 		this.formData.userIds = this.personListp[this.index2];
					// 	}
					// }
					console.log(this.formData)
					uni.request({
						url: this.$http + '/biz/bizReport/check',
						data: this.formData,
						header: {
							token: uni.getStorageSync("token")
						},
						method: 'POST',
						success: (res) => {
							if (res.statusCode == 200 && res.data.code == 0) {
								this.modalName = null;
								uni.showToast({
									icon: 'none',
									title: '操作成功！'
								});
								this.loadData();
							} else {
								uni.showToast({
									icon: 'none',
									title: '操作失败，请重试！'
								});
							}
						},
						fail: function() {
							uni.showToast({
								icon: 'none',
								title: '服务器请求超时！'
							});
						}
					})
				}else{
					this.formData.status = 505;
					uni.request({
						url: this.$http + '/biz/bizReport/pass',
						data: this.formData,
						header: {
							token: uni.getStorageSync("token")
						},
						method: 'POST',
						success: (res) => {
							if (res.statusCode == 200 && res.data.code == 0) {
								this.modalName = null;
								uni.showToast({
									icon: 'none',
									title: '操作成功！'
								});
								this.loadData();
							} else {
								uni.showToast({
									icon: 'none',
									title: '操作失败，请重试！'
								});
							}
						},
						fail: function() {
							uni.showToast({
								icon: 'none',
								title: '服务器请求超时！'
							});
						}
					})
				}
			}
		}
	}
</script>

<style>
	.inputbox {
		margin: 0 auto;
		width: 700rpx;
		height: 80rpx;
		border: 1px #D0D0D0 solid;
		border-radius: 10rpx;
		font-size: 30rpx;
		color: #116AB7;
		line-height: 80rpx;
		padding-left: 20.41rpx;
		display: flex;
		margin-top: 10rpx;
	}

	.f_input {
		text-align: left;
		width: 500rpx;
		height: 50rpx;
		margin-left: 20.83rpx;
		margin-top: 15rpx;
	}

	.selectbox {
		margin: 0 auto;
		width: 700rpx;
		height: 80rpx;
		border-radius: 10rpx;
		font-size: 30rpx;
		color: #116AB7;
		line-height: 80rpx;
		display: flex;
		margin-top: 10rpx;
		justify-content: space-between;
	}
	.no-data {
		  text-align: center;
	}
</style>
